package eerbaar.v2.graphics.rect;

import java.awt.Dimension;
import java.awt.Rectangle;


public class RectOp {

    public static Rectangle2 expand(Rectangle rect, int x, int y) {
        Rectangle2 rect2 = new Rectangle2(rect);
        int left = rect2.getLeft() - x;
        int top = rect2.getTop() - y;
        int width = (int) rect2.getWidth() + x;
        int height = (int) rect2.getHeight() + y;
        return new Rectangle2(left, top, width, height);
    }

    public static Rectangle2 expand(Rectangle2 rect, Dimension size) {
        Rectangle2 rect2 = new Rectangle2(rect);
        int width = (int) rect2.getWidth() + (int) size.getWidth();
        int height = (int) rect2.getHeight() + (int) size.getHeight();
        return new Rectangle2(rect2.getLeft(), rect2.getTop(), width, height);
    }

    public static Rectangle2 join(Rectangle2 anchor, Dimension size) {
        Rectangle2 anchor2 = new Rectangle2(anchor);
        int left = anchor2.getLeft();
        int top = anchor2.getTop();
        int width = Math.max((int) anchor2.getWidth(), (int) size.getWidth());
        int height = (int) anchor2.getHeight() + (int) size.getHeight();
        return new Rectangle2(left, top, width, height);
    }

    public static Rectangle2 subtract(Rectangle2 rect, Dimension point) {
        Rectangle2 rect2 = new Rectangle2(rect);
        int left = rect2.getLeft() - (int) point.getWidth();
        int top = rect2.getTop() - (int) point.getHeight();
        return new Rectangle2(left, top, (int) rect2.getWidth(),
                (int) rect2.getHeight());
    }

}
